import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='', charset='utf8', db='unicom')  # 链接mysql
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)


def insert():
    order = "insert into admin(username,password,mobile) values(%s,%s,%s);"
    while True:
        user = input('用户名：')
        if user.upper() == 'Q':
            break
        pwd = input('密码：')
        mobile = input('电话：')
        cursor.execute(order, [user, pwd, mobile])
        conn.commit()

    cursor.close()
    conn.close()

def select():#获得的是一个字典
    order="select * from admin;"
    cursor.execute(order)
    data_list=cursor.fetchall()
    for item in data_list:
        print(item)
    cursor.close()
    conn.close()

def delete(id):
    order="delete from admin where id=%s;"
    cursor.execute(order,[id,])
    conn.commit()
    cursor.close()
    conn.close()

def update(val,id):

    order="update admin set mobile=%s where id =%s"
    cursor.execute(order, [val,id ])
    conn.commit()
    cursor.close()
    conn.close()

if __name__=='__main__':

    select()
